import type { EnumDto, OptionDto } from '@/api/types'

/**
 * getKeyToEnum(UserLevelEnum, [1, 2])
 * @param data 原始枚举/对象
 * @param arr 需要转为label、value的枚举值，若未传则返回全部
 * @returns {label: string, value: string | number}[]
 */
export function getKeyToEnum(data: { [key: string | number]: string | number }, arr?: (number | string)[]) {
    const keys = Object.keys(data) as (number | string)[]

    if (!arr) {
        return Object.keys(data).filter(item => Number.isNaN(Number(item))).map(item => ({
            label: item,
            value: data[item],
        }))
    }
    return arr.filter((item) => {
        return keys.includes(item)
    }).map(item => ({
        label: data[item],
        value: item,
    })) as OptionDto[]
}

// 将key value 对象数组 转换为 键值对对象
export function getKeyValueToObject(data: EnumDto[]): { [key: string | number]: string | number } {
    const obj = {} as { [key: string | number]: string | number }
    data.forEach((item) => {
        obj[item.value] = item.label
    })
    return obj
}

export enum PlatformCnEnum {
    'mp-alipay' = '支付宝小程序',
    'mp-weixin' = '微信小程序',
}

export enum SalaryStatusEnum {
    待领薪 = 0,
    已领薪 = 1,
    停止发薪 = 2,
    进行中 = 3,
    领取失败 = 4,
}

export enum PayAccountFlagEnum {
    支付宝支付 = 20001,
    微信支付 = 10001,
}

export enum SalaryTypeEnum {
    advance = 1,
    salary = 0,
}

export enum StatusEnum {
    审核中 = 0,
    未通过 = 1,
    待领取 = 2,
    已领取 = 3,
    停止发薪 = 4,
    领取失败 = 5,
    进行中 = 6,
}

export enum LogoutStatusEnum {
    PROCESS = 0,
    SUCCESS = 1,
    FAIL = 2,
}

export enum PlatformEnum {
    WEIXIN = 0,
    ALIPAY = 1,
}
